﻿// =============================================================================
// XPathDebugger And Examples Viewer.xaml.cs
// Copyright (c) 2013 TNTTechnologies Inc.
// =============================================================================

#region

using System.Windows.Controls;
using System.Windows.Data;
using System.Xml;

#endregion

namespace XMLViewer{
    /// <summary>
    ///     Interaction logic for Viewer.xaml
    /// </summary>
    public partial class Viewer : UserControl{
        private XmlDocument _xmldocument;

        public Viewer(){
            this.InitializeComponent();
        }

        public XmlDocument xmlDocument{
            get{
                return this._xmldocument;
            }
            set{
                this._xmldocument = value;
                this.BindXMLDocument();
            }
        }

        private void BindXMLDocument(){
            if (this._xmldocument == null){
                this.xmlTree.ItemsSource = null;
                return;
            }

            XmlDataProvider provider = new XmlDataProvider();
            provider.Document = this._xmldocument;
            Binding binding = new Binding();
            binding.Source = provider;
            binding.XPath = "child::node()";
            this.xmlTree.SetBinding(TreeView.ItemsSourceProperty, binding);
        }
    }
}